import { GameEngine } from "./GameEngine";
import { GameObject } from "./GameObject";


export class Behaviour {

    _active: boolean = false;

    get active() {
        return this._active;
    }

    set active(value: boolean) {
        this._active = value;
        const allSystems = this.engine.getSystems();
        for (const system of allSystems) {
            if (value) {
                system.onAddBehaviour(this.gameObject, this)
            }
            else {
                system.onRemoveBehaviour(this.gameObject, this);
            }
        }
    }

    engine: GameEngine;

    static behavioursStore: { [uuid: number]: Behaviour } = {};

    static get(uuid: number) {
        return Behaviour.behavioursStore[uuid];
    }

    uuid: number = 0;

    constructor() {
        this.uuid = createUUID();
        Behaviour.behavioursStore[this.uuid] = this;
    }

    gameObject: GameObject;

    onStart() {
    }

    onUpdate(duringTime: number) {
    }

    onFixUpdate(durtingTime: number) {

    }

    onEnd() {
    }
}


let uuIdIndex = 0;
function createUUID() {
    return uuIdIndex++;
}
